package com.haixiaoke.flat.messageCenter.controller;

import com.haixiaoke.auth.AuthCheck;
import com.haixiaoke.saas.common.constant.MessageConstants;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.messageCenter.domain.PushRecord;
import com.haixiaoke.saas.messageCenter.service.IPushRecordService;
import com.haixiaoke.saas.system.BaseController;
import com.haixiaoke.token.FrontTokenComponent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 推送记录信息Controller
 *
 * @author xiaolong
 * @date 2024-11-20
 */
@RestController
@RequestMapping("/front/flat/messageCenter/pushRecord")
public class FlatPushRecordController extends BaseController {
    @Autowired
    private IPushRecordService pushRecordService;
    @Autowired
    private FrontTokenComponent frontTokenComponent;

    /**
     * 查询推送记录信息列表
     */
    @GetMapping("/list")
    @AuthCheck
    public TableDataInfo list(PushRecord pushRecord) {
        startPage();
        pushRecord.setUserId(frontTokenComponent.getLoginUser().getUser().getUserId());
        pushRecord.setPushChannel(MessageConstants.PUSH_CHANNEL_RENTER_APPLET);
        pushRecord.setMessageType(MessageConstants.ORDINARY_MESSAGE_TYPE_IN);
        List<PushRecord> list = pushRecordService.selectPushRecordList(pushRecord);
        return getDataTable(list);
    }


    /**
     * 统计消息未读数量
     */
    @GetMapping(value = "/statistics")
    @AuthCheck
    public AjaxResult getStatistics() {
        return success(pushRecordService.getStatisticsByUserId(frontTokenComponent.getLoginUser().getUser().getUserId()));
    }
}
